//
// Created by 尚衍硕 on 18/9/28.
//
#include <iostream>
#include <pthread.h>
#include <gtest/gtest.h>

using namespace std;

#define NUM_THREADS 5

struct thread_data{
    int thread_id;
    char *message;
};


void *PrintHello(void *threadarg)
{
    struct thread_data *my_data;
    my_data = (struct thread_data *)threadarg;
    cout << "Thread ID : " << my_data->thread_id << endl;
    cout << "thread message : " << my_data->message << endl;
    pthread_exit(NULL);
}

int test_main()
{
    pthread_t threads[NUM_THREADS];
    struct thread_data td[NUM_THREADS];
    int rc;
    int i;
    for( i = 0; i<NUM_THREADS; ++i)
    {
        cout << "main() create thread : " << i << endl;
        td[i].thread_id = i;
        td[i].message = (char *)"Thread message";
        rc = pthread_create(&threads[i],NULL,PrintHello,(void *)&td[i]);
        if(rc)
        {
            cout << "Error:unable to create thread," << rc << endl;
            exit(-1);
        }

    }
    pthread_exit(NULL);
    return 0;
}











